package org.myspringframework.test;

import org.myspringframework.beans.BeansException;
import org.myspringframework.beans.factory.BeanFactory;
import org.myspringframework.beans.factory.aware.BeanClassLoaderAware;
import org.myspringframework.beans.factory.aware.BeanFactoryAware;
import org.myspringframework.beans.factory.aware.BeanNameAware;
import org.myspringframework.beans.factory.config.DisposableBean;
import org.myspringframework.beans.factory.config.InitializingBean;
import org.myspringframework.context.ApplicationContext;
import org.myspringframework.context.annotation.Autowired;
import org.myspringframework.context.annotation.Component;
import org.myspringframework.context.annotation.Value;
import org.myspringframework.context.aware.ApplicationContextAware;

@Component
public class UserService  implements IUserService,InitializingBean, DisposableBean , BeanNameAware, BeanClassLoaderAware, ApplicationContextAware, BeanFactoryAware {
    @Value("${myvalue}")
    int i;
    //@Autowired
    UserController userController;
    ClassLoader classLoader;
    BeanFactory beanFactory;
    String beanName;
    ApplicationContext applicationContext;

    public static void testStatic(){
        System.out.println("static");
    }

    public final void testFinal(){
        System.out.println("final");
    }

    public UserService(){
        System.out.println("userService无参构造");
    }
    public UserService(int i){
        this.i=i;
        System.out.println("UserService构造器方法：i="+i);
    }
    public void querry(){
        System.out.println("UserService执行querry()");
        System.out.println(i);
        System.out.println("classLoader:"+classLoader);
        System.out.println("beanName:"+beanName);
        System.out.println("beanfactory:"+beanFactory);
        System.out.println("applicationcontext:"+applicationContext);
    }

    public void initmethod(){
        System.out.println("init-method");
    }
    public void destroymethod(){
        System.out.println("destroy-method");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("init");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader=classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory=beanFactory;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName=name;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }

    @Override
    public BeanFactory getBeanFactory(){
        return this.beanFactory;
    }

    public UserController getUserController(){
        return userController;
    }
}
